# -*- coding: utf-8 -*-,
# @File : test0.py,
# @Author : lidong,
# @IDEA: PyCharm
# @Time :  2022/4/26 09:52

import threading
lock = threading.Lock()
# 假定这是你的银行存款:
balance = 0


def change_it(n):
    # 先存后取，结果应该为0:
    global balance
    balance = balance + n
    balance = balance - n


def run_thread(n):
    for i in range(2000000):
        lock.acquire()# 先获取锁
        try:
            change_it(n)
        finally:
            lock.release()# 改完了一定要释放锁:


t1 = threading.Thread(target=run_thread, args=(5,))
t2 = threading.Thread(target=run_thread, args=(8,))
t1.start()
t2.start()
t1.join()
t2.join()
print(balance)